<?php
namespace app\common\system\logic;

use app\common\BaseLogic;

class PassportLogic extends BaseLogic
{
    private $loginTimesCacheName = 'login_times:';

    // 检测登录次数
    public function getLoginTimes($nickname)
    {
        $cacheName = $this->loginTimesCacheName.$nickname;
        $times = (int)$this->redis->get($cacheName);
        return $times;
    }

    // 写入等
    public function incrLoginTimes($nickname)
    {
        $cacheName = $this->loginTimesCacheName.$nickname;
        $this->redis->multi();
        $this->redis->incr($cacheName);
        $this->redis->expire($cacheName, 900);
        $this->redis->exec();
    }

    public function resetLoginTimes($nickname)
    {
        $cacheName = $this->loginTimesCacheName.$nickname;
        $this->redis->del($cacheName);
    }
}